package org.rency.mq.activemq.listener.factory.concurrent;

import org.rency.mq.activemq.listener.factory.AbstractMessageListenerContainer;

import java.util.concurrent.ExecutorService;

public class ConcurrentMessageListenerContainer extends AbstractMessageListenerContainer {
	private int maxThreadsHold = Runtime.getRuntime().availableProcessors() * 2;
	private int coreThreadsHold = Runtime.getRuntime().availableProcessors() / 2;
	private ExecutorService executorService;
	
	@Override
	public void initMessageListener() {
		ConcurrentMessageListener messageListener = new ConcurrentMessageListener();
		messageListener.setCoreThreadsHold(coreThreadsHold);
		messageListener.setMaxThreadsHold(maxThreadsHold);
		messageListener.setMessageHandler(getMessageHandler());
		messageListener.setMessageListenerContainer(this);
		if(executorService != null){
			messageListener.setExecutorService(executorService);
		}
		
		setMessageListener(messageListener);
	}

	public void setMaxThreadsHold(int maxThreadsHold) {
		this.maxThreadsHold = maxThreadsHold;
	}

	public void setCoreThreadsHold(int coreThreadsHold) {
		this.coreThreadsHold = coreThreadsHold;
	}

	public void setExecutorService(ExecutorService executorService) {
		this.executorService = executorService;
	}

}
